package com.emergency.controller;

import com.emergency.http.WrapMapper;
import com.emergency.http.Wrapper;
import com.emergency.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Validated
@RestController
@RequestMapping("/common")
@Api(tags = "公共API")
public class CommonController {

    @Resource
    private StreetService streetService;

    @Resource
    private VillageService villageService;

    @Resource
    private DutiesService dutiesService;

    @Resource
    private IndustryService industryService;

    @Resource
    private SuppliesTypeService suppliesTypeService;

    @Resource
    private TeamTypeService teamTypeService;

    @Resource
    private DepartmentService departmentService;

    /**
     * 乡镇/街道列表
     *
     * @param type 1-乡镇/街道 2-部门、企业
     * @return Wrapper
     */
    @ApiOperation("乡镇/街道列表")
    @GetMapping("/getStreetList")
    public Wrapper<?> getStreetList(@ApiParam("类型") @RequestParam(required = false) Integer type) {
        return WrapMapper.ok(streetService.getStreetList(type));
    }

    /**
     * 村/社区列表
     *
     * @return Wrapper
     */
    @ApiOperation("村/社区列表")
    @GetMapping("/getVillageList")
    public Wrapper<?> getVillageList() {
        return WrapMapper.ok(villageService.getVillageList());
    }

    /**
     * 行业及特长列表
     *
     * @return Wrapper
     */
    @ApiOperation("行业及特长列表")
    @GetMapping("/getIndustryList")
    public Wrapper<?> getIndustryList() {
        return WrapMapper.ok(industryService.getIndustryList());
    }

    /**
     * 职称列表
     *
     * @return Wrapper
     */
    @ApiOperation("职称列表")
    @GetMapping("/getDutiesList")
    public Wrapper<?> getDutiesList() {
        return WrapMapper.ok(dutiesService.getDutiesList());
    }

    /**
     * 部门列表
     *
     * @param type 部门类型
     * @return Wrapper
     */
    @ApiOperation("部门列表")
    @PostMapping("/getDepartmentList")
    public Wrapper<?> getDepartmentList(@ApiParam("部门类型") @RequestParam(required = false) Integer type) {
        return WrapMapper.ok(departmentService.getDutiesList(type));
    }

    /**
     * 物资类型列表
     *
     * @return Wrapper
     */
    @ApiOperation("物资类型列表")
    @GetMapping("/getSuppliesTypeList")
    public Wrapper<?> getSuppliesTypeList() {
        return WrapMapper.ok(suppliesTypeService.getSuppliesTypeList());
    }

    /**
     * 救援队伍类型列表
     *
     * @return Wrapper
     */
    @ApiOperation("救援队伍类型列表")
    @GetMapping("/getTeamTypeList")
    public Wrapper<?> getTeamTypeList() {
        return WrapMapper.ok(teamTypeService.getTeamTypeList());
    }

    /**
     * 获取部门联系人列表
     *
     * @param id 部门ID
     * @return Wrapper
     */
    @ApiOperation("获取部门联系人列表")
    @GetMapping("/getDepartmentLinkmanList")
    public Wrapper<?> getDepartmentLinkmanList(@ApiParam("部门ID") @NotNull(message = "id 不能为空") @RequestParam Long id) {
        return WrapMapper.ok(departmentService.getDepartmentLinkmanList(id));
    }
}
